package com.becca.cake.model.voucher;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.multipart.MultipartFile;

import com.becca.cake.core.exception.ServiceException;
import com.becca.cake.model.advert.AdvertModel;

/**
 * 抵用券广告实体
 * @copyright  尊星(上海)信息科技有限公司
 * @author Mouwanming
 * @date 2016年9月6日 上午11:15:17
 */
public class VoucherAdvertModel implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8933834876864725228L;
	
	private Integer            id;
    /**广告标题*/
    private String             advTitle;
    /**广告图片url*/
    private String             advPicPath;
    /**状态(0:禁用 1:正常)*/
    private Byte               advStatus;
    /**排序*/
    private Byte               advOrder;
    /**开始时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date               startDate;
    /**结束时间*/
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date               endDate;
    /**创建时间*/
    private Date               createdDate;
    /**创建人*/
    private String             createdName;
    /**修改时间*/
    private Date               updatedDate;
    /**修改人*/
    private String             updatedName;
    
    /**广告状态：（禁用：0）*/
    public static final Byte ADV_STATUS_FORBIDDEN = 0;
    /**广告状态：（正常：1）*/
    public static final Byte ADV_STATUS_NOMAL = 1;
    
    /**广告编号不能为空*/
    public static final String ADVERT_NOT_NULL ="广告编号不能为空";
    /**广告信息不存在*/
    public static final String ADVERT_NOT_EXISTE ="广告信息不存在";
    /**广告标题不能为空*/
    public static final String ADVERT_TITILE_NULL ="广告标题不能为空";
    /**广告图片不能为空*/
    public static final String ADVERT_PICPATH_NULL ="广告图片不能为空";
    /**广告排序不能为空*/
    public static final String ADVERT_ORDER_NULL ="广告排序不能为空";
    /**广告开始时间不能为空*/
    public static final String ADVERT_STARTDATE_NULL ="广告开始时间不能为空";
    /**广告结束时间不能为空*/
    public static final String ADVERT_ENDDATE_NULL ="广告结束时间不能为空";
    /**广告状态不能为空*/
    public static final String ADVERT_STATUS_NULL ="广告状态不能为空";
    /**图片上传失败*/
    public static final String PICTURE_UPDLOAD_FAILED = "图片上传失败";
    
    /**该广告已被禁用*/
    public static final String ADVERT_STATUS_FORBIDDEN_EXIST ="该广告已被禁用";
    /**该广告已启用*/
    public static final String ADVERT_STATUS_NOMAL_EXIST ="该广告已启用";
    
    /**未修改排序*/
    public static final String UPD_ORDER_NULL ="未修改排序";

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getAdvTitle() {
		return advTitle;
	}

	public void setAdvTitle(String advTitle) {
		this.advTitle = advTitle;
	}

	public String getAdvPicPath() {
		return advPicPath;
	}

	public void setAdvPicPath(String advPicPath) {
		this.advPicPath = advPicPath;
	}

	public Byte getAdvStatus() {
		return advStatus;
	}

	public void setAdvStatus(Byte advStatus) {
		this.advStatus = advStatus;
	}

	public Byte getAdvOrder() {
		return advOrder;
	}

	public void setAdvOrder(Byte advOrder) {
		this.advOrder = advOrder;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getCreatedName() {
		return createdName;
	}

	public void setCreatedName(String createdName) {
		this.createdName = createdName;
	}

	public Date getUpdatedDate() {
		return updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}

	public String getUpdatedName() {
		return updatedName;
	}

	public void setUpdatedName(String updatedName) {
		this.updatedName = updatedName;
	}
    
	/**
     * 查询广告对象时校验ID是否为空
     * @param advertId
     */
    public static void validAdvId(Integer advertId){
        if (advertId == null) {
            throw new ServiceException(VoucherAdvertModel.ADVERT_NOT_NULL);
        }
    }
    
    /**
     * 修改广告状态时校验
     * @param advertId
     * @param advStatus
     */
    public static void validAdvStatus(Integer advertId,String advStatus){
        if (advertId == null) {
            throw new ServiceException(VoucherAdvertModel.ADVERT_NOT_NULL);
        }
        if (advStatus == null) {
            throw new ServiceException(VoucherAdvertModel.ADVERT_STATUS_NULL);
        }
    }
    
    /**
     * 添加、修改广告校验
     * 
     * @param voucherAdvertModel
     * @param files
     */
    public static void validInsertOrUpdateAdvert(VoucherAdvertModel voucherAdvertModel, MultipartFile files){
        if(voucherAdvertModel == null){
            throw new ServiceException(AdvertModel.ADVERT_NOT_EXISTE);
        }
        if(StringUtils.isEmpty(voucherAdvertModel.getAdvTitle())){
            throw new ServiceException(VoucherAdvertModel.ADVERT_TITILE_NULL);
        }
        if(voucherAdvertModel.getId() == null && files.isEmpty()){
            throw new ServiceException(VoucherAdvertModel.ADVERT_PICPATH_NULL);
        }
        if(voucherAdvertModel.getAdvOrder() == null){
            throw new ServiceException(VoucherAdvertModel.ADVERT_ORDER_NULL);
        }
        if(voucherAdvertModel.getStartDate() == null){
            throw new ServiceException(VoucherAdvertModel.ADVERT_STARTDATE_NULL);
        }
        if(voucherAdvertModel.getEndDate() == null){
            throw new ServiceException(VoucherAdvertModel.ADVERT_ENDDATE_NULL);
        }
    }
    
    /**
     * 广告排序不能为空
     * @param list
     */
    public static void validUpdateOrders(List<VoucherAdvertModel> list){
       for (VoucherAdvertModel voucherAdvertModel : list) {
           if(voucherAdvertModel.getAdvOrder() == null){
               throw new ServiceException(VoucherAdvertModel.ADVERT_ORDER_NULL);
           }
       }
    }

}
